package com.youbug.recreation.controller;


import com.youbug.common.vo.R;
import com.youbug.recreation.entity.GamePlayer;
import com.youbug.recreation.entity.GameRoom;
import com.youbug.recreation.service.IGamePlayerService;
import com.youbug.recreation.service.IGameRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 联机坦克 前端控制器
 * </p>
 *
 * @author youbug
 * @since 2023-07-16
 */
@RestController
@RequestMapping("/tank-online")
public class GameRoomController {

    @Autowired
    private IGameRoomService gameRoomService;
    @Autowired
    private IGamePlayerService gamePlayerService;

    @PostMapping("/getGameRooms")
    public R<List<GameRoom>> getGameRooms(){

        List<GameRoom> list = gameRoomService.list();

        return R.ok(list);
    }
    @Deprecated
    @PostMapping("/saveGamePlayer")
    public R<Boolean> saveGamePlayer(@RequestBody GamePlayer player){

        boolean save = gamePlayerService.save(player);

        return R.ok(save);
    }

    @PostMapping("/add")
    public R<Boolean> add(@RequestBody GameRoom gameRoom){

        boolean save = gameRoomService.save(gameRoom);

        return  R.ok(save);
    }

    @GetMapping("/closeRoom/{id}")
    public R<Boolean> closeRoom(@PathVariable String id){

        boolean remove = gameRoomService.removeById(id);

        return  R.ok(remove);
    }
}

